package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    public void work(BookList bookList){
        Scanner sc=new Scanner(System.in);
        System.out.println("添加图书");
        System.out.println("请输入图书名：");
        String name=sc.nextLine();
        int size= bookList.getUsedsize();
        for(int i=0;i<size;i++){
            Book book=bookList.getBook(i);
            if(book.getName().equals(name)){
                System.out.println("这本书已经存在");
                System.out.println(book);
                return;
            }
        }
        System.out.println("请输入你要新增的图书的作者: ");
        String author=sc.nextLine();
        System.out.println("请输入你要新增的图书的价格: ");
        int price=sc.nextInt();
        sc.nextLine();
        System.out.println("请输入你要新增的图书的类型: ");
        String type=sc.nextLine();
        Book book=new Book(name,author,price,type);
        bookList.setBook(bookList.getUsedsize(),book );
        bookList.setUsedsize(bookList.getUsedsize()+1);
        System.out.println("添加图书成功!");
        return;
    }
}
